/******************************************************************************
 *      Mestrado em Ciência da Computação - UFMS
 *		Redes de Computadores - Prof. Dr. Ronaldo Alves Ferreira
 *		Alunos: Geraldo Landre, Marcel Tolentino, Vinícius Bueno
 *****************************************************************************/
/* tcppersist.c - tcppersist */

#include "tcpfms.h"
#include "tcb.h"
#include "tcp.h"
#include "my_socket.h"


extern int tmset(int port, int portlen, void *msg, int time);

/*------------------------------------------------------------------------
 *  tcppersist - manipula eventos enquanto a send window está fechada
 *------------------------------------------------------------------------
 */
int tcppersist( int tcbnum, int event)
{
    struct	tcb *ptcb = (struct tcb*)&tcbtab[tcbnum];

    if (event != PERSIST && event != SEND)
        return OK;	/* ignore everything else */
    tcpsend(tcbnum, TSF_REXMT);
    ptcb->tcb_persist = min(ptcb->tcb_persist<<1, TCP_MAXPRS);
    tmset(thread_getport(output_thread), TCPQLEN, MKEVENT(PERSIST, tcbnum),
        ptcb->tcb_persist);
    return OK;
}
